﻿using Autofac;
using Autofac.Core;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Misc.TabManager.Controllers;
using Nop.Plugin.Misc.TabManager.Data;
using Nop.Plugin.Misc.TabManager.Domain;
using Nop.Plugin.Misc.TabManager.Services;
using Nop.Web.Framework.Mvc;

namespace Nop.Plugin.Misc.TabManager.Infrastructure
{
    public class DependencyRegistrar : IDependencyRegistrar
    {
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            builder.RegisterType<TabManagerService>().As<ITabManagerService>().InstancePerLifetimeScope();

            this.RegisterPluginDataContext<TabManagerContext>(builder, "nop_object_context_tabmanager");

            builder.RegisterType<TabManagerController>()
                .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"));
 
            //override required repository with our custom context
            builder.RegisterType<EfRepository<Tab>>()
                .As<IRepository<Tab>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_tabmanager"))
                .InstancePerLifetimeScope();
           
            //builder.RegisterType<EfRepository<Tab>>()
            //    .As<IRepository<Tab>>()
            //    .WithParameter<EfRepository<Tab>
            //    , ConcreteReflectionActivatorData, SingleRegistrationStyle>(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_messagedesign")).InstancePerHttpRequest<EfRepository<Tab>, ConcreteReflectionActivatorData, SingleRegistrationStyle>(new object[0]);

       }

        public int Order
        {
            get { return 2; }
        }
    }
}
